<template>
	<!-- 获取绑定的房屋列表 -->
	<view>
		<TopNavCustom title="房屋芯造"></TopNavCustom>
		<view class="container">
			<view v-for="(house, index) in houseList" :key="index">
				<!-- <house-item :house="house" :title="title"></house-item> -->
				<view class="card" @click.stop="goto(house)">
					<view class="houses-item-left">
						<image :src="getSrc(house.houseTypeImage)" class="houses-pic"></image>
					</view>
					<!-- 房屋右侧信息区域 -->
					<view class="houses-item-right">
						<view class="top-title">
							<text class="onsale">{{ house.status }}</text>
							<text class="slogan">户型：{{ house.estateType }}</text>
						</view>
						<view class="houses-name">{{ house.building }}栋 {{ house.unit }}单元
							{{ house.num }}号
						</view>
						<view class="houses-info">建筑面积：{{house.constructionArea}}㎡</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import $C from '@/common/config.js'
	export default {
		created() {
			this.getHouseList();
		},
		data() {
			return {
				houseList: [],
				title: "",
				_url: ''
			};
		},
		methods: {
			getSrc(ids){
				if (typeof ids == undefined || ids == null || ids == '') {
					return
				}
				let idArray = ids.split(',')
				let id = idArray[0]
				if ((typeof id) != undefined && id != '') {
					let _src = $C.baseUrl + '/file/download?fileId=' + id
					return _src
				}
			},
			goto(house) {
				let _item = decodeURIComponent(JSON.stringify(house));
				uni.setStorageSync("houseId", house.estateId);
				uni.navigateTo({
					url: this._url + "?item=" +
						_item,
				});
			},
			async getHouseList() {
				const data = await uni.$H.post(
					"/userEstateMap/getByQuery", {
						roleId: "4",
						userId: uni.getStorageSync("userId"),
						estateType: 1,
						floorId: uni.getStorageSync("estateId"),
					}, {
						authCode: true,
					}
				);
				if (data.status === 0) {
					if (data.body.length != 0) {
						let _list = [];
						for (let i = 0; i < data.body.length; i++) {
							if (data.body[i].realEstateVO.saleStatus == 2) {
								data.body[i].realEstateVO.status = "在售";
							} else if (data.body[i].realEstateVO.saleStatus == 1) {
								data.body[i].realEstateVO.status = "未售";
							} else {
								data.body[i].realEstateVO.status = "已售";
							}
							_list.push(data.body[i].realEstateVO);
						}
						this.houseList = _list;
					}
				} else {
					uni.$showMsg(data.message);
				}
			},
		},
		onLoad(params) {
			console.log(params)
			this.title = params.title;
			if (params.title == '房屋节点') {
				this._url = '/pages/ihome/housing_node/housing_node'
			} else {
				this._url = '/pages/ihome/house_building_select_check_items/house_building_select_check_items'
			}

		},
	};
</script>

<style lang="scss" scoped>
	.container {
		padding: 20rpx 30rpx 0 30rpx;

		// background-color: #efefef;
	}

	.card {
		padding: 20rpx;
		background-color: #ffffff;
		border-radius: 20rpx;
		border: 1rpx solid #efefef;
		display: flex;
		flex-direction: row;
		margin-bottom: 20rpx;

		.houses-item-left {
			.houses-pic {
				width: 200rpx;
				height: 200rpx;
				display: block;
			}
		}

		.houses-item-right {
			margin-left: 40rpx;
			display: flex;
			// justify-content: space-around;
			flex-direction: column;

			.top-title {
				display: inline-flex;
				flex-direction: row;
				flex-grow: 2;

				.onsale {
					background: linear-gradient(90deg, #e93423 0%, #fb6858 100%);
					border-radius: 4rpx;
					font-size: 24rpx;
					color: #ffffff;
					width: 66rpx;
					height: 30rpx;
					text-align: center;
				}

				.slogan {
					margin-left: 17rpx;
					font-size: 24rpx;
					font-weight: 500;
					color: #333333;
				}
			}

			.houses-name {
				font-size: 28rpx;
				font-weight: bold;
				color: #333333;
				flex-grow: 4;
			}

			.houses-info {
				flex-grow: 4;
				font-size: 24rpx;
				font-weight: 500;
				color: #999999;
			}

			.houses-price {
				font-size: 28rpx;
				font-weight: bold;
				color: #e62129;
			}
		}
	}
</style>
